﻿using System;
using System.Collections.Generic;
using System.Text;
using FunctionalCLR;
using FunctionalCLR.Core;

namespace FunctionalCLR.Core.Function.String {
    public class ReplaceNode : FuncNode {

        public ReplaceNode()
            : base() {
            base.Value = "replace";
        }

        public override FuncNode GetReversedFunction(int index) {
            throw new NotImplementedException();
        }

        public override object Evaluate() {
            int length = Children.Count;
            if (length < 3) {
                throw new ArgumentException();
            }

            string expr = Children[length - 1].Evaluate().ToString();
            string from = Children[length - 2].Evaluate().ToString();
            string to = Children[length - 3].Evaluate().ToString();

            return expr.Replace(from, to);
        }
    }
}
